package com.example.travelhelper.config;

import com.example.travelhelper.interceptors.JwtInterceptor;
import com.example.travelhelper.interceptors.PageViewInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private PageViewInterceptor pageViewInterceptor;
    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("图片配置生效");
        String filePath = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\image\\";
        System.out.println(filePath);
        registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(pageViewInterceptor).addPathPatterns("/travel");
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**");

    }
}
